package joat.application.ui;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ConversationListAdapter extends BaseAdapter {
	protected List<ConversationListEntry> list;
	protected Activity activity;
	protected LayoutInflater inflater;

	public ConversationListAdapter(Activity activity, List<ConversationListEntry> list) {
		super();
		this.list = list;
		this.activity = activity;
		this.inflater = LayoutInflater.from(activity);
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int index) {
		return list.get(index);
	}

	public long getItemId(int index) {
		return index;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			convertView = inflater.inflate(R.layout.conversation_list_view, null);
		}
		ImageView imageView = (ImageView)convertView.findViewById(R.id.imageViewConversationEntry);
		TextView textView = (TextView)convertView.findViewById(R.id.textViewConversationEntry);
		
		imageView.setImageResource(list.get(position).imageResourceId);
		textView.setText(list.get(position).message);
		textView.setTextColor(list.get(position).color);
		return convertView;
	}

}
